<template>
	<view class="container">
		<headerTop title="质保单"></headerTop>
		<block v-if="listData.length == 0">
			<view class="all_empty">
				<u-empty mode="data"></u-empty>
			</view>
		</block>
		<block v-else>
			<u-cell-group>
				<block v-for="(item, index) in listData" :key="index">
					<u-cell
						:title="item.goods_name"
						:label="item.create_time"
						:value="item.price"
						isLink
						:url="'/pages/warranty/detail/detail?user_code=' + item.user_code"
					></u-cell>
				</block>
			</u-cell-group>
		</block>

		<u-loadmore v-if="listData.length > searchForm.limit" :status="status" :loading-text="loadingText" :loadmore-text="loadmoreText" :nomore-text="nomoreText" />
	</view>
</template>

<script>
export default {
	data() {
		return {
			searchForm: {
				limit: 10,
				page: 1
			}
		};
	},
	onLoad({ ExternalUserID, welcome_code }) {
		if (ExternalUserID) {
			uni.setStorage({
				key: 'ExternalUserID',
				data: ExternalUserID
			});
		}
		if (welcome_code) {
			uni.setStorage({
				key: 'welcome_code',
				data: welcome_code
			});
		}
		this.$initConfig().then((_) => {
			this.getInfo();
		});
	},
	methods: {
		getInfo(is_add = false) {
			let _this = this;
			_this
				.$http('order/getUserOrderList', {
					..._this.searchForm
				})
				.then((res) => {
					if (res.code) {
						if (is_add) {
							_this.listData = _this.listData.concat(res.data.data);
						} else {
							_this.listData = res.data.data;
						}
						console.log(_this.listData);
						if (_this.listData.length >= res.data.total) {
							this.status = 'nomore';
						} else {
							this.status = 'loadmore';
						}
					}
				});
		}
	}
};
</script>

<style lang="scss" scoped>
.container {
	background-color: #fff;
}
</style>
